<?php

namespace app\api\controller;

use app\BaseController;
use app\model\PaymentChannels;
use app\model\PaymentMethods;
use app\model\Shops;
use app\model\ShopsPayments;

/**
 *  主控制器
 */
class Index extends BaseController
{
    public function index()
    {   
        // 添加支付渠道
        $payment = new PaymentChannels();
        $payment->save([
            'channel_name'          => '杉德钱包直连',
            'pay_code'              => 'ShanDeDirect',
            'channel_code'          => 'shande',
            'pay_url'               => 'https://faspay-oss.sandpay.com.cn/pay/h5/cloud',
            'find_url'              => 'https://cap.sandpay.com.cn/v4/elecaccount/ceas.elec.member.status.query',
            'channel_rate'          => '3.5'
        ]);
        $payment_id = $payment->id;
        if ($payment_id > 0){
            // 添加支付方式
            $method = new PaymentMethods();
            $method->saveAll([
                ['method_name'=>'微信', 'method_code'=>'wxpay', 'is_show'=>true],
                ['method_name'=>'支付宝', 'method_code'=>'alipay', 'is_show'=>true],
                ['method_name'=>'杉德钱包', 'method_code'=>'shande', 'is_show'=>true],
                ['method_name'=>'卡密', 'method_code'=>'cardpay', 'is_show'=>true],
            ]);

            // 添加商户
            $shop = Shops::create([
                'shop_name'    => '测试商户',   
                'shop_code'    => '00001',  
                'company_main' => '测试商户',  
                'shop_status'  => 1
            ]);

            // 添加商户支付方式
            ShopsPayments::create([
                'shop_id'               => $shop->id,
                'channel_id'            => $payment_id,
                'method_id'             => 1,
                'appid'                 => '6888802124093',
                'private_key'           => '6888802124093.pfx',
                'public_key'            => 'sand_pro.cer',
                'notify_url'            => 'http://183.221.111.185:8002/api/charge/sdd/notify',
                'return_url'            => 'http://183.221.111.185:8002'
            ]);
        }

        //
        return "添加数据成功";
    }

    public function hello($name = 'ThinkPHP8')
    {
        return 'hello,' . $name;
    }
}
